package com.sgai.zero_robot.utils;

import android.content.Context;
import android.util.DisplayMetrics;

/**
 * Describe :
 * Created by zzw on 2024/3/4
 */
public class DeviceUtils {

    public static int dp2px(Context context, int dp) {
        float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dp * scale + 0.5f);
    }


    /**
     * dp获取dip
     * @param dp
     * @return
     */
    public static float convertDpToPixel(float dp, Context context) {
        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        return (dp * displayMetrics.density);
    }
}